home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / language / dl_exsrc.zoo / memicmp.c < prev    next >
C/C++ Source or Header  |  1994-07-03  |  878b  |  40 lines

  1. /* modified from the memcmp() from Henry Spencer's stringlib */
  2.  
  3. #include <stddef.h>
  4. #include <string.h>
  5.  
  6. /*
  7.  * memicmp - compare bytes, ignoring case
  8.  *
  9.  * CHARBITS should be defined only if the compiler lacks "unsigned char".
  10.  * It should be a mask, e.g. 0377 for an 8-bit machine.
  11.  */
  12.  
  13. #ifndef CHARBITS
  14. #    define    UNSCHAR(c)    ((unsigned char)(c))
  15. #else
  16. #    define    UNSCHAR(c)    ((c)&CHARBITS)
  17. #endif
  18.  
  19. int                /* <0, == 0, >0 */
  20. memicmp(s1, s2, size)
  21. const void * s1;
  22. const void * s2;
  23. size_t size;
  24. {
  25.     register const char *scan1;
  26.     register const char *scan2;
  27.     register size_t n;
  28.  
  29.     scan1 = (const char *) s1;
  30.     scan2 = (const char *) s2;
  31.     for (n = size; n > 0; n--)
  32.     if (toupper(*scan1) == toupper(*scan2)) {
  33.         scan1++;
  34.         scan2++;
  35.     } else
  36.         return(UNSCHAR (toupper(*scan1)) - UNSCHAR (toupper(*scan2)));
  37.  
  38.     return(0);
  39. }
  40.